<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :md='4' :sm='8'>
            <a-form-item label='所属项目'>
              <a-select show-search :filter-option='filterOption' v-model='queryParam.projectId' placeholder='请输入所属项目'
                        style='margin-right: 20px'>
                <a-select-option value=''>请选择项目</a-select-option>
                <a-select-option v-for='item in projectList' :label='item.name' :value='item.id' :key='item.id'>
                  <span style='float: left'>{{ item.name }}</span>
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='4' :sm='8'>
            <a-form-item label='设备序列号'>
              <a-input placeholder='请输入设备序列号' v-model='queryParam.deviceSn'></a-input>
            </a-form-item>
          </a-col>

          <a-col :md='4' :sm='8'>
            <a-form-item label='通行人姓名'>
              <a-input placeholder='通行人姓名' v-model='queryParam.peopleName'></a-input>
            </a-form-item>
          </a-col>
          <a-col :md='4' :sm='8'>
            <a-form-item label='通行类型'>
              <j-dict-select-tag v-model='queryParam.throughType' placeholder='请选择通行类型'
                                 dictCode='through_type' />
            </a-form-item>
          </a-col>
          <a-col :md='4' :sm='8'>
            <a-form-item label='通信结果'>
              <j-dict-select-tag v-model='queryParam.resultType' placeholder='请选择通行类型'
                                 dictCode='through_result_type' />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter='24'>
          <a-col :md='10' :sm='8'>
            <a-form-item label='创建时间'>
              <j-date v-model='queryParam.createTime_begin' :showTime='true' date-format='yyyy-MM-dd HH:mm:ss'
                      style='width:45%' placeholder='请选择开始时间'></j-date>
              <span style='width: 10px;'>~</span>
              <j-date v-model='queryParam.createTime_end' :showTime='true' date-format='yyyy-MM-dd HH:mm:ss'
                      style='width:45%' placeholder='请选择结束时间'></j-date>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        class='j-table-force-nowrap'
        @change='handleTableChange'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text,record'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' :preview='record.id' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

      </a-table>
    </div>
  </a-card>
</template>

<script>


import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getProjectList } from '@api/api'


export default {
  name: 'ThroughList',
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      description: '通行配置表管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName'
        },
        {
          title: '通行人姓名',
          align: 'center',
          dataIndex: 'peopleName'
        },
        {
          title: '通行结果',
          align: 'center',
          dataIndex: 'resultType_dictText'

        },

        {
          title: '照片',
          width: 80,
          align: 'center',
          dataIndex: 'picture',
          customRender: (record) => {
            let r = record
            return (
              <img
                style='max-width:35px;max-height:35px;min-height:20px;min-width:20px;text-align:center;cursor:pointer;border:1px #BFBFBF solid;padding: 2px 2px 2px 2px;background-color:white;'
                preview={r}
                src={record}
              ></img>
            )
          }
        },
        {
          title: ' 体温',
          align: 'center',
          dataIndex: 'temperature'
        },
        {
          title: '通行类型',
          align: 'center',
          dataIndex: 'throughType_dictText'
        },
        {
          title: '设备序列号',
          align: 'center',
          dataIndex: 'deviceSn'
        },
        {
          title: '设备名称',
          align: 'center',
          dataIndex: 'deviceName'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime'
        }

      ],
      url: {
        list: '/through/list',
        detail: '/through/detail'
      },
      projectList:[],
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
    this.initProjectList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    filterOption(input, option) {
      let com = option.componentOptions
      let name = String(com.propsData.label)
      if (name.toLowerCase().includes(input.toLowerCase())) {
        return true
      }
    },
    initProjectList() {
      getProjectList().then((res)=>{
        if(res.success){
          this.projectList = res.result
        }
      })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'int', value: 'accessType', text: '进出类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceSn', text: '设备序列号', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'deviceName',
        text: '设备名称',
        dictTable: '',
        dictText: '',
        dictCode: ''
      })
      fieldList.push({ type: 'int', value: 'throughType', text: '通行类型（黑白名单）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'peopleName', text: '通行人姓名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectId', text: '项目id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'picture', text: '照片', dictCode: '' })
      fieldList.push({ type: 'string', value: 'temperature', text: ' 体温', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'datetime', value: 'updateTime', text: '更新日期' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
</style>